﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 飞机大战
{
    /// <summary>
    /// 子弹的父类
    /// </summary>
    internal class Bullet : Game
    {
        private Image imgbullet;

        /// <summary>
        /// 记录子弹威力
        /// </summary>
        public int power { get; set; }

        public Bullet(PlaneFather pf, Image img, int speed, int power) :
   base(pf.X + pf.Width / 2 - 30, pf.Y + pf.Height / 2 - 50, img.Width, img.Height, speed, 0, pf.dir)
        {
            this.imgbullet = img;
            this.power = power;
        }

        /// <summary>
        /// 重写Game的抽象成员
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(Graphics g)
        {
            this.Move();
            g.DrawImage(imgbullet, this.X, this.Y, this.Width / 2, this.Height / 2);
        }

        public override void Move()
        {
            switch (this.dir)
            {
                case Direction.up:
                    this.Y -= this.Speed;
                    break;
                case Direction.down:
                    this.Y += this.Speed;
                    break;
            }

            //子弹超出边界后
            if (this.Y <= 0)
            {
                this.Y = -100;
            }
            if (this.Y >= 780)
            {
                this.Y = 1000;
            }
        }
    }
}
